package com.yanyilu.qiubite.jpa;

import com.yanyilu.qiubite.entity.StoryIndex;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface StoryIndexJpa extends JpaRepository<StoryIndex,Integer> {
    @Query(value = "select * from story_index where user_id = :userId",nativeQuery = true)
    StoryIndex findByUserId(@Param("userId")Integer userid);

    @Query(value = "select * from story_index where user_id = :userId and part_id =:partId",nativeQuery = true)
    StoryIndex findbyUserIdAndPartId(@Param("userId")Integer userid, @Param("partId")Integer partId);

    @Modifying
    @Query(value = "delete from story_index where user_id = :userId",nativeQuery = true)
    void deleteByUserId(@Param("userId")Integer userId);
}
